﻿//初始化入口
$(function() {

    InitLoadData();
});

function InitLoadData() {
    $('#RoomJoinNum').empty().append(0);
    $('#CarportJoinNum').empty().append(0);
    $('#txtTotal').numberbox('setValue', 0);
    $('#txtBankMoney').numberbox('setValue', 0);
    $('#txtBanksurplus').numberbox('setValue', 0);
    
    requestAjax('../Controller.aspx?controller=AccountController&method=GetTotalFee', {}, function(data) {
        $('#txtTotal').numberbox('setValue', data.totalfee);

        $("#txtBankMoney").bind("change", function() {
            var Banksurplus = parseFloat($("#txtTotal").val()) - parseFloat($("#txtBankMoney").val());
            $('#txtBanksurplus').numberbox('setValue', Banksurplus);
        });
    });

    requestAjax('../Controller.aspx?controller=AccountController&method=GetJoinNum', {}, function(data) {
        $('#RoomJoinNum').empty().append(data.roomjoinNum);
        $('#CarportJoinNum').empty().append(data.carportjoinNum);
    });

    $('#chargelistGrid').datagrid('options').url = '../Controller.aspx?controller=AccountController&method=GetChargeList';
    $('#chargelistGrid').datagrid('reload');
    
    $('#itemlistGrid').treegrid('options').url = '../Controller.aspx?controller=AccountController&method=GetItemClassList';
    $('#itemlistGrid').treegrid('reload');
}

//交款
function btn_Account() {
    if (formvalidate('formaccount') == false) return false;
    if (parseInt($('#txtTotal').val()) == 0) {
            $.messager.alert('提示', "没有需要交款金额！", 'info');
            return false;
        }
        
    $.messager.confirm('询问', '是否进行交款？', function(r) {
        if (r) {
            requestAjax('../Controller.aspx?controller=AccountController&method=SaveAccount', { Total: $('#txtTotal').val(), BankMoney: $('#txtBankMoney').val(), Banksurplus: $('#txtBanksurplus').val() }, function(data) {
                InitLoadData();
            });
        }
    });
}